import { Body, Controller, Get, Param, Post } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { User } from "../entities/user.entity";
import { UserService } from "../service/user.service";

@Controller('user')
@ApiTags('user')
export class UserController {
    constructor(
        private readonly userService: UserService
    ) { }

    @Post()
    @ApiOperation({
        summary: "创建用户",
    })
    async create(@Body() user: User) {
        return await this.userService.create(user);
    }

    @Get("/:username")
    @ApiOperation({
        summary: "根据用户名查询用户",
    })
    async findOne(@Param("username") username: string) {
        return await this.userService.findOne(username);

    }

    @Get()
    @ApiOperation({
        summary: "查询所有用户",
    })
    async findAll() {
        return await User.find();
    }
}